package com.wx.mapper;

import com.wx.dto.UserPageQueryDTO;
import com.wx.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {
    /*根据条件查询用户数*/
    Integer getUserCount(UserPageQueryDTO userPageQueryDTO);

    /*根据条件查询用户*/
    List<User> getUserList(UserPageQueryDTO userPageQueryDTO);

    /*根据用户名查询用户*/
    @Select("select * from user where username = #{username}")
    User getByUsername(String username);

    /*根据用户id查询用户*/
    @Select("select * from user where id = #{id}")
    User getById(Integer id);

    /*插入用户数据*/
    @Insert("insert into " +
            "user(id, username, password, create_time, name, sex, phone, id_number, avatar, is_frozen,b_number,return_num) " +
            "values(#{id},#{username},#{password},#{createTime},#{name},#{sex},#{phone},#{idNumber},#{avatar},#{isFrozen},#{bNumber},#{returnNum})")
    Integer save(User user);

    /*修改用户信息*/
    Integer update(User user);


    /*b_number加一*/
    @Update("update user set b_number = b_number + 1 where id = #{borrowId}")
    void increaseBNum(Integer borrowId);

    /*return_num加一*/
    @Update("update user set return_num = return_num + 1 where id = #{id}")
    void increaseRNum(Integer id);
}
